package cn.shadow.module.scene;

import cn.shadow.moulde.ISender;
import io.netty.buffer.ByteBuf;
import lombok.Data;

import static java.lang.Math.abs;
import static java.lang.Math.max;


/**
 * 600像素一个格子
 *
 *
 * */
@Data
public class HeroViewObj extends ViewObj implements ISender {
    /**
     * 最小视野范围
     */
    public static final int MIN_VIEW_RANGE = 2;

    /**
     * 最大视野范围
     */
    public static final int MAX_VIEW_RANGE = 6;

    private ISender sender;

    /**
     * 视野范围
     */
    private int viewRange;

    /**
     * 新的视野范围
     */
    private int newViewRange;

    /**
     * 距离中心最大的距离，max(dX,dY)
     */
    private int centerMaxDistance;

    public HeroViewObj(long id, int viewId) {
        super(id, viewId);
        this.viewRange = MIN_VIEW_RANGE;
        this.newViewRange = viewRange;
    }

    public HeroViewObj(long id, ISender sender) {
        super(id);
        this.sender = sender;
        this.viewRange = MIN_VIEW_RANGE;
        this.newViewRange = viewRange;
    }

    public void calcCenterMaxDistance(int centerX, int centerY) {
        this.centerMaxDistance = max(abs(centerX - getX()), abs(centerY - getY()));
    }

    private int getCenterMaxDistance() {
        return centerMaxDistance;
    }

    @Override
    public void sendMessage(ByteBuf buffer) {
//        this.sender.sendMessage(buffer);
    }

    /**
     * 修改视野大小
     */
    public int syncViewRange() {
        this.viewRange = newViewRange;
        return newViewRange;
    }
}
